package com.taotao.portal.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.pojo.TbUser;
import com.taotao.portal.pojo.CartItem;
import com.taotao.portal.pojo.Order;
import com.taotao.portal.service.CartService;
import com.taotao.portal.service.OrderService;


@Controller
@RequestMapping("/order")
public class OrderController {
	@Autowired
	private CartService cartService;
	@Autowired
	private OrderService orderService;
	@RequestMapping("/order-cart")
	public String showOrderCart(HttpServletRequest request,
			HttpServletResponse response,Map<String,Object> map){
		List<CartItem> cartList = cartService.getCartItemList(request, response);
		map.put("cartList", cartList);
		return "order-cart";
	}
	
	@RequestMapping("/create")
	public String createOrder(Order order,Map<String,Object> map,HttpServletRequest request){
		TbUser user=(TbUser) request.getAttribute("user");
		order.setUserId(user.getId());
		order.setBuyerNick(user.getUsername());
		String orderId = orderService.creatOrder(order);
		map.put("orderId", orderId);
		map.put("payment", order.getPayment());
		map.put("date",new DateTime().plusDays(3).toString("yyyy-MM-dd"));
		return "success";
	}
}
